﻿using System;
using System.Threading;
using System.IO;
using System.Reflection;

namespace Fjaspx.UI.Web
{
    /// <summary>
    /// 远程下载解压文件
    /// </summary>
    public partial class Update : AdminPage
    {
        /// <summary>
        ///  Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {}
        /// <summary>
        /// 下载压缩文件到本地，并解压到相应的目录 Handles the Click event of the Button_ZIP control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Button_ZIP_Click(object sender, EventArgs e)
        {

            Assembly assembly = Assembly.LoadFile(Server.MapPath("~/bin/Fjaspx.UI.Web.dll"));
            Response.Write("当前版本:"+assembly.GetName().Version.ToString());
           
            Fjaspx.Common.DownloadFile Down = new Fjaspx.Common.DownloadFile();
            Down.StrUrl = ___CmsConfigValue("UpdateServer");
            Down.StrFileName = Server.MapPath("~/temp.zip");
            if (Down.Download())
            {
                string UpdatePath = Server.MapPath("~/Update/temp.zip");
                bool Error = Fjaspx.Common.ZIP.UnpackFiles(UpdatePath, Server.MapPath("~/"));
                if (Error)
                {
                    FileDel(UpdatePath);
                    Response.Write("下载解压所需更新文件成功 ！ <a href='/admin/index.aspx'>点击开始更新</a>");
                }
                else
                {
                    FileDel(UpdatePath);
                    Response.Write("解压失败！");
                }
            }
            else { Response.Write(Down.strError); }
        }
        void FileDel(string FileName) { File.Delete(FileName); }
    }
}
